#include "renderImoBlock.h"
#define SCALE 4

renderImoBlock::renderImoBlock(float init_red, float init_green, float init_blue)
{
	//Initialize the variables
	r = init_red; g = init_green; b = init_blue;
	// Load the texture!
	loadOpenGL2DTextureBMP("wall.bmp", &imoBlock_texture, GL_RGB);
}

renderImoBlock::~renderImoBlock(void)
{
}

// This draw method is intended to draw the shapes, set the material
// and appropriately texture the shapes generated.
void renderImoBlock::draw(float init_x, float init_y, float init_z)
{
	x = (init_x) * SCALE;
	y = (init_y) * SCALE;
	z = ((init_z) * SCALE) - ( .2 * SCALE );


	//	/* Set up material properties. */
	GLfloat mat_ambient[] = { 0.2, 0.2, 0.2, 1 };
	GLfloat mat_diffuse[] = { 0.2, 0.2, 0.2, 1 };
	GLfloat mat_specular[] = { 0.8, 0.8, 0.8, 1 };

	glPushMatrix();

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, imoBlock_texture);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialf(GL_FRONT, GL_SHININESS, 10.0 ); /* No effect if specular == 0 */
		glTranslatef(x, y, z + (SCALE*.4));
		glScalef(1,1,.8);
		glColor3f(r, g, b); 
				//START THE QUADS!
		glBegin(GL_QUADS);


glNormal3f(0,0,-1);
			glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
			glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, 0.0);
			glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, 0.0);
			glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, 0.0);

			glNormal3f(0,0,1);
			glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, SCALE);
			glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
			glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
			glTexCoord2f(1.0, 0.0); glVertex3f(0.0, SCALE, SCALE);

			glNormal3f(-1,0,0);
			glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
			glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
			glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
			glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);

			glNormal3f(1,0,0);
			glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
			glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
			glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
			glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);

			glNormal3f(0,-1,0);
			glTexCoord2f(0.0, 0.0); glVertex3f(0.0, SCALE, 0.0);
			glTexCoord2f(0.0, 1.0); glVertex3f(0.0, SCALE, SCALE);
			glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 0.0, SCALE);
			glTexCoord2f(1.0, 0.0); glVertex3f(0.0, 0.0, 0.0);

			glNormal3f(0,1,0);
			glTexCoord2f(0.0, 0.0); glVertex3f(SCALE, SCALE, 0.0);
			glTexCoord2f(0.0, 1.0); glVertex3f(SCALE, SCALE, SCALE);
			glTexCoord2f(1.0, 1.0); glVertex3f(SCALE, 0.0, SCALE);
			glTexCoord2f(1.0, 0.0); glVertex3f(SCALE, 0.0, 0.0);
		glEnd();
		glTranslatef(-x, -y, - (z + (SCALE*.4)));
		glDisable(GL_TEXTURE_2D);

	glPopMatrix();
}